package com.guanghua.brick.html.tag;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.guanghua.brick.security.SecurityUtil;

public class PermissionContentTag extends BodyTagSupport {
	private static Log logger = LogFactory.getLog(PermissionContentTag.class);
	
	private String function = null;
	private String property = null;
	private boolean avail = true;

	public int doEndTag() throws JspException {
		String sql = "";
		if (avail) {
			sql = SecurityUtil.contentPermissionFilter(function, (HttpServletRequest)pageContext.getRequest(), property);
		}
		
		try {
			JspWriter out = pageContext.getOut();
			out.println(sql);
		} catch (IOException e) {
			logger.error("io exception on print permission content html", e);
		}
		return BodyTagSupport.EVAL_PAGE;
	}

	public boolean isAvail() {
		return avail;
	}

	public void setAvail(boolean avail) {
		this.avail = avail;
	}

	public String getFunction() {
		return function;
	}

	public void setFunction(String function) {
		this.function = function;
	}

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

}
